//package org.vs.service.impl;
//
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.vs.test.contract.DemoContract;
//import org.vs.test.contract.SimpleStorageSolSimpleStorage;
//import org.vs.test.contract.TestSol;
//import org.vs.service.BlockchainService;
//import org.web3j.crypto.Credentials;
//import org.web3j.protocol.Web3j;
//import org.web3j.protocol.admin.Admin;
//import org.web3j.protocol.admin.methods.response.PersonalUnlockAccount;
//import org.web3j.protocol.core.*;
//import org.web3j.protocol.core.methods.request.Transaction;
//import org.web3j.protocol.core.methods.response.*;
//import org.web3j.tx.Contract;
//import org.web3j.tx.Transfer;
//import org.web3j.tx.gas.ContractGasProvider;
//import org.web3j.tx.gas.StaticGasProvider;
//import org.web3j.utils.Convert;
//
//import javax.annotation.Resource;
//import java.io.IOException;
//import java.math.BigDecimal;
//import java.math.BigInteger;
//import java.util.concurrent.ExecutionException;
//
//@Service
//@Slf4j
//public class BlockchainServiceImpl implements BlockchainService {
//    @Resource
//    private Web3j web3j;
//    @Resource
//    private Credentials credentials;
//    @Resource
//    private ContractGasProvider contractGasProvider;
//    @Resource
//    private Admin admin;
//
//    @Override
//    public String selectBalance(String address) throws IOException {
//        DefaultBlockParameter defaultBlockParameter =
//                new DefaultBlockParameterNumber(web3j.ethBlockNumber().send().getBlockNumber());
//        EthGetBalance ethGetBalance = web3j.ethGetBalance(address, defaultBlockParameter).send();
//        if (ethGetBalance == null) {
//            log.error(ethGetBalance.getError().getData(), ethGetBalance.getError().getMessage());
//        }
//
//        System.out.println(web3j.ethGetBalance(credentials.getAddress(), defaultBlockParameter).send().getBalance().toString());
//
//
//        BigInteger ethBalance = ethGetBalance.getBalance();
//        BigDecimal ethBalanceTurn = Convert.fromWei(ethBalance.toString(), Convert.Unit.ETHER);
//        log.debug("余额 : " + ethBalanceTurn.toString());
//
//        return ethBalance.toString();
//    }
//
//    @Override
//    public boolean miner(String address) throws IOException {
//        web3j.ethMining().send();
//        return false;
//    }
//
//    String contractAddress = "";
//
//    @Override
//    public Object deployment() throws Exception {
//        Request<?, PersonalUnlockAccount> request = admin.personalUnlockAccount(credentials.getAddress(), "123", BigInteger.valueOf(3000));
//        PersonalUnlockAccount account = request.send();
//        System.out.println(account.accountUnlocked());
//        DemoContract contract = DemoContract.deploy(web3j, credentials,
//               new StaticGasProvider(BigInteger.valueOf(200000), BigInteger.valueOf(20000000))).send();
//        contractAddress = contract.getContractAddress();
//        return contractAddress;
//    }
//
//    @SneakyThrows
//    @Override
//    public Object load() throws IOException, ExecutionException, InterruptedException {
//        Request<?, PersonalUnlockAccount> request = admin.personalUnlockAccount(credentials.getAddress(), "123", BigInteger.valueOf(3000));
//        PersonalUnlockAccount account = request.send();
//        DemoContract contract = DemoContract
//                .load("0xc4330733b8f7b6796fa29c1828efd88a273c191a",
//                        web3j,
//                        credentials,
//                        new StaticGasProvider(BigInteger.valueOf(200000), BigInteger.valueOf(20000000)));
//
//        System.out.println(contract.isValid());
//        System.out.println(contract.sayHelloWorld().send());
//        return null;
//    }
//
//
//}
